using Godot;
using System;

public partial class EnterGameUi : Control
{
	[Signal]
	public delegate void EnterGameUIStateChangedEventHandler(bool show);

	private AnimationPlayer _animation;

	public override void _Ready()
	{
		_animation = GetNode<AnimationPlayer>("AnimationPlayer");
        _animation.AnimationFinished += Signal_AnimationFinished;
	}


    public override void _GuiInput(InputEvent @event)
    {
		switch (@event)
		{
			case InputEventKey:
				_animation.Play("leave");
				ReleaseFocus();
				break;

			default:
				break;
		}
	}

	public void ShowEnterUI()
	{
		Visible = true;
		CallDeferred(MethodName.GrabFocus);
		_animation.Play("enter");
	}

	// GODOT - Signals
    private void Signal_AnimationFinished(StringName animName)
    {
		var animation = animName.ToString();
		if (animation == "enter")
		{
			EmitSignal(SignalName.EnterGameUIStateChanged, true);
		}
        else if (animation == "leave")
        {
			Visible = false;
            EmitSignal(SignalName.EnterGameUIStateChanged, false);
        }
    }
}
